package cn.pugle.mianshi;

/**
 * <p> Created by tzp on 2017/9/6.
 */
public class IPLib {
    public static void main(String[] args) {
        System.out.println(ipToNumber("255.255.255.255"));
        System.out.println(ipToNumber("255.255.255.2"));
        System.out.println(ipToNumber("0.0.1.0"));

    }

    private static Long ipToNumber(String ip) {
        Long ips = 0L;
        String[] numbers = ip.split("\\.");
        for (int i = 0; i < 4; ++i) {
            ips = ips << 8 | Integer.parseInt(numbers[i]);
        }
        return ips;
        //final String[] ipNums = ip.split("\\.");
//        return (Long.parseLong(ipNums[0]) << 24)
//                + (Long.parseLong(ipNums[1]) << 16)
//                + (Long.parseLong(ipNums[2]) << 8)
//                + (Long.parseLong(ipNums[3]));
    }

    private static Integer ipToNumber1(String ip) {
        Integer ips = 0;//256,2 56,25 6,256
        String[] numbers = ip.split("\\.");
        for (int i = 0; i < 4; ++i) {
            ips = ips << 8 | Integer.parseInt(numbers[i]);
        }
        return ips;
    }
}
